package com.huayun.weexutil;

import android.app.Application;
import android.content.Context;

import com.alibaba.android.bindingx.plugin.weex.BindingX;
import com.huayun.components.HuayunInput;
import com.taobao.weex.InitConfig;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.common.WXException;

/**
 * Description:
 * Created on 2018/11/27 0027 14:37:24
 * author:Ahuangshang
 */
public class WexInit {
    private static Application application;

    public static void init(Application app) {
        application = app;
        try {
            initWXE();
        } catch (WXException e) {
            e.printStackTrace();
        }
    }

    public static Context getContext() {
        if (application == null) {
            throw new RuntimeException(" used weexutilLibs need init");
        } else {
            return application;
        }
    }

    private static void initWXE() throws WXException {
        InitConfig config = new InitConfig.Builder().setImgAdapter(new ImageAdapter()).build();
        WXSDKEngine.initialize(application, config);
        WXSDKEngine.registerModule("event", WXEventModule.class);
        WXSDKEngine.registerModule("net", WXNetModule.class);
        WXSDKEngine.registerComponent("huaYunInput", HuayunInput.class);
        initBindingX();
    }

    private static void initBindingX() throws WXException {
        BindingX.register();
    }
}
